from fastapi import FastAPI, Form, HTTPException, Request, Depends
from fastapi.responses import JSONResponse
from router import app1, version_config, version_update
from fastapi.middleware.cors import CORSMiddleware
import uvicorn

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(app1.router)
app.include_router(version_config.router)
app.include_router(version_update.router)


# 全局欢迎页
@app.get("/")
async def read_root():
    return {"Hello": "World"}


# 全局异常处理
@app.exception_handler(Exception)
async def exceptionHandler(request: Request, exc: Exception):
    return JSONResponse(
        status_code=418,
        content={"message": f"Oops! {exc} did something. There goes a rainbow..."},
    )


if __name__ == '__main__':
    uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=True, debug=True, workers=10)
